home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
pascal
/
spoc88.zip
/
PROASM.ZIP
/
OPEN.ASM
< prev
next >
Wrap
Assembly Source File
|
1988-06-09
|
2KB
|
61 lines
COMMENT @*************************************************************
This program receives the address of an ASCIIZ string (a string
that ends with a binary zero). The string contains the name of
a file that is to be opened. The program opens the file and
returns an integer that acts as a file reference (also called
a file handle). We return the file handle by placing its
address on the stack.
| 10 | <--- FIRST PARM (INPUT PARM)
| 9 |
| 8 |
| 7 |
| 6 | <--- SECOND PARM (OUTPUT PARM) 32 BIT POINTER
| 5 |
| 4 |
| 3 |
| 2 | RETURN ADDRESS
| 1 |
| 0 | BP
--------
TOP OF STACK
---------------------------------------------------------------------@
A_PROG SEGMENT BYTE
ASSUME CS: A_PROG
PUBLIC open_0
open_0 PROC FAR
MOV SI,DS ;save SI
PUSH BP ;save BP on stack
MOV BP,SP ;BP = SP
MOV DX, [BP]+ 10 ;get offset address of filename
MOV DS, [BP]+ 12 ;get segment addr of filename
SUB AL,AL ;Set Al to 0 for read access
MOV AH,3Dh ;Specify open function
INT 21h ;Invoke the interrupt
JC FAILURE
LDS DI,DWORD PTR [BP] + 6 ;make DI point to output parm
;;;;;;;;; SUB AH,AH ;
MOV [DI],AX ;Move AX to FileHANDLE
POP BP ;Restore BP
MOV DS,SI ;Restore DS
RET 8 ;pop the parms off the stack
FAILURE:
MOV AX,0FFh ;0FFh will be error flag
LDS DI,DWORD PTR [BP] + 6 ;Make DI point to output parm
MOV [DI],AX ;Move error value to FileHANDLE
POP BP ;Restore BP
MOV DS,SI ;Restore DS
RET 8 ;pop the parms off the stack
open_0 ENDP
A_PROG ENDS
END